package com.ruoyi.web.controller.tool;

import com.ruoyi.common.annotation.Anonymous;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.system.domain.SysFactory;
import com.ruoyi.system.service.ISysFactoryService;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 工厂信息Controller
 * 
 * @author spark
 * @date 2023-07-23
 */
@ApiOperation("工厂信息管理")
@RestController
@RequestMapping("/test/factory")
@Anonymous
public class TestFactoryController extends BaseController
{
    @Autowired
    private ISysFactoryService sysFactoryService;

    /**
     * 查询工厂信息列表
     */
    @ApiOperation("查询工厂信息列表")
    @GetMapping("/list")
    public TableDataInfo list(SysFactory sysFactory)
    {
        startPage();
        List<SysFactory> list = sysFactoryService.selectSysFactoryList(sysFactory);
        return getDataTable(list);
    }

    /**
     * 导出工厂信息列表
     */
    //@ApiOperation("导出工厂信息列表")
    @Log(title = "工厂信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, SysFactory sysFactory)
    {
        List<SysFactory> list = sysFactoryService.selectSysFactoryList(sysFactory);
        ExcelUtil<SysFactory> util = new ExcelUtil<SysFactory>(SysFactory.class);
        util.exportExcel(response, list, "工厂信息数据");
    }

    /**
     * 获取工厂信息详细信息
     */
    @ApiOperation("获取工厂信息详细信息")
    @GetMapping(value = "/{factoryId}")
    public AjaxResult getInfo(@PathVariable("factoryId") Long factoryId)
    {
        return success(sysFactoryService.selectSysFactoryByFactoryId(factoryId));
    }

    /**
     * 新增工厂信息
     */
    @ApiOperation("新增工厂信息")
    @Log(title = "工厂信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody SysFactory sysFactory)
    {
        return toAjax(sysFactoryService.insertSysFactory(sysFactory));
    }

    /**
     * 修改工厂信息
     */
    @ApiOperation("修改工厂信息")
    @Log(title = "工厂信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SysFactory sysFactory)
    {
        return toAjax(sysFactoryService.updateSysFactory(sysFactory));
    }

    /**
     * 删除工厂信息
     */
    @ApiOperation("删除工厂信息")
    @Log(title = "工厂信息", businessType = BusinessType.DELETE)
	@DeleteMapping("/{factoryIds}")
    public AjaxResult remove(@PathVariable Long[] factoryIds)
    {
        return toAjax(sysFactoryService.deleteSysFactoryByFactoryIds(factoryIds));
    }
}
